<template>
  <div class="wrapper">


    <img src="http:/192.168.1.59:8088/qkupload/img/714616fd-9567-4560-baf0-82df6c3a10a7.jpg" alt="" width="100px">


    <div class="add_style">
      <span>指定跳转地址:</span>
      <Input v-model="val" style="width: 400px"></Input>
    </div>
    <div class="add_style">
      <span>公告通知:</span>
      <div>
        <upload :echo="echo" @returnValue="returnValue"></upload>
      </div>
    </div>
    <div class="add_style">
      <Button size="small" type="primary" @click="ok">修改</Button>
    </div>
  </div>
</template>

<script>
  import upload from '../module/upload.vue';

  export default {
    components: {upload,},
    data() {
      return {
        echo: '',
        val: '',
        id: '',
        file: ''
      }
    },
    mounted() {
      window.scrollTo(0, 0);
      this.get(this.$api.url + '/float/window/list')
    },
    methods: {
      returnValue(data) {
        this.echo = '';
        this.file = data;
      },
      ok() {
        if (this.val != '') {
          let obj = {
            id: this.id,
            uri: this.val,
          };
          this.post(this.$api.url + '/float/window/add', obj)
        }
      },
      /*get请求*/
      get(url) {
        this.$axios.get(url).then((res) => {
          if (res.data.code == 200) {
            this.id = res.data.data[0].id;
            this.val = res.data.data[0].uri;
            this.echo = res.data.data[0].imgUri;
          }
        });
      },
      /*post请求*/
      post(url, data) {
        let _this = this;
        let formData = new FormData();
        formData.append("file", this.file);
        formData.append("floatWindow", JSON.stringify(data));
        let config = {
          headers: {'Content-Type': 'multipart/form-data'}
        };
        this.$axios.post(url, formData, config).then(function (res) {
          _this.get(_this.$api.url + '/float/window/list')
        })
      },
    },
  }
</script>

<style scoped>
  .wrapper {
    margin: 10px;
  }

  .add_style {
    padding-top: 10px;
  }

  .add_style > span {
    font-size: 14px;
    font-weight: bold;
    display: inline-block;
    width: 140px;
  }
</style>
